﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DetailedView.aspx.cs" Inherits="Management.DetailedView" %>
<%@ Import Namespace="Management" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Personal Organizer 2015</title>
    <link rel="stylesheet" type="text/css" href="/Resources/css/detailed.css"/>
    <link rel="stylesheet" type="text/css" href="/Resources/css/default.css"/>
    <script type="text/javascript" src="/Resources/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/Resources/js/default.js"></script>
    <script type="text/javascript" src="/Resources/js/detailed.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:HiddenField runat="server" ID="__EVENTTARGET"/>
        <asp:HiddenField runat="server" ID="__EVENTARGUMENT"/>
        <h1 style="text-align: center; margin: auto; font-family: Curlz MT;">ПЕРСОНАЛЬНЫЙ ОРГАНАЙЗЕР 2015. УПРАВЛЕНИЕ ВРЕМЕНЕМ</h1>
        <button id="homeBtn" onclick="return clickHome();"></button>
        <div id="content">
        <table border="1" style="float: left;">
            <tr>
                <td id="goalHead">Цели<div id="addGoal" title="Добавить новую цель"></div></td>
                <td id="taskHead">Задачи</td>
            </tr>
            <tr>
                <td style="height: 18px;" colspan = "2"></td>
            </tr>
            <% var week = Int32.Parse(Request.QueryString["week"]);
                var goals = new List<Goal>();
                var goalsPar = Request.QueryString["goals"];
                if (goalsPar == "all")
                {
                    //goals = dao.GetGoalsWithExistingTime(week);
                    goals = dao.GetAllGoals();
                }
                else
                {
                    var goal = dao.GetGoal(Int32.Parse(Request.QueryString["goal"]));
                    if (goal != null)
                        goals.Add(goal);
                }
                var i = 1;
                foreach (var goal in goals)
                { %>
                   <tr>
                       <td><span style="float: left;"><%= goal.Name %></span>
                           <div class="dropDownGoal" id="<%= "dropDownGoal" + i %>" title="Меню цели">
                               <div id="<%= "dropDownGoalVal" + i %>" class="dropDownGoalVal" style="display: none">
                                   <div onclick="addNewTask('<%= goal.Name %>')" class="newTaskDiv">Новая задача</div>
                                   <button class="delGoal" onclick="__doPostBack('removeGoal','<%= goal.Name %>')">Удалить цель</button>
                               </div>
                           </div>
                       </td>
                        <td>
                            <% var tasks = new List<Task>();
                               if (goalsPar == "all")
                               {
                                   tasks = dao.GetAllTasks(goal.Id);
                               }
                               else
                               {
                                   var task = dao.GetTask(Int32.Parse(Request.QueryString["task"]), goal.Id);
                                   if (task!=null)
                                       tasks.Add(task);
                               }
                               foreach (var task in tasks)
                               { %>
                                 <div class="task">
                                     <div class="taskName" onclick="showDescription('<%=dao.GetTaskDescription(goal.Id, task)%>', '<%=task.name %>~<%=goal.Name %>', '<%=task.status %>');"><%= task.name %></div>
                                     <button class="removeTask" onclick="__doPostBack('removeTask', '<%= goal.Name %>~<%= task.name %>')" title="Удалить задачу"></button>
                                 </div>
                            <% } %>
                        </td>
                    </tr>
               <% i++;
                } %>
            <tr>
                <td style="height: 18px; font-weight: bold; text-align: right" colspan = "2">Общее время:</td>
            </tr>
        </table>
        
        <% Task existingTask = null;
            for (i = 0; i < dao.weekDays.Length; i++)
           {%>
               <table border="1" style="float: left;">
                   <tr>
                       <td style="text-align: center; min-width: 120px;"><%=dao.weekDays[i] %></td>
                   </tr>
                   <tr>
                       <td style="text-align: center; min-width: 120px;"><%=dao.GetDateByWeekNumberAndDay(week, dao.weekDays[i]).ToShortDateString() %></td>
                   </tr>
                   <% foreach (var goal in goals)
                      {%>
                          <tr>
                              <td>
                                  <% var tasks = new List<Task>();
                                     if (goalsPar == "all")
                                     {
                                         tasks = dao.GetAllTasks(goal.Id);
                                         if (tasks.Count == 0)
                                         {%>
                                            <div class="inputText"></div>
                                         <%}
                                     }
                                     else
                                     {
                                         var task = dao.GetTask(Int32.Parse(Request.QueryString["task"]), goal.Id);
                                         if (task != null)
                                         {
                                             existingTask = task;
                                             tasks.Add(task);
                                         }
                                     }
                                     foreach (var task in tasks)
                                     {%>
                                        <div class="inputText"><input maxlength="4" type="text" class="inputBox toUse" readonly="readonly" id="<%=dao.weekDays[i]%>-<%=week%>-<%=task.Id%>" value="<%=dao.GetTimeByWeekTaskDay(week, task.Id, dao.weekDays[i]) %>"/></div>
                                   <%} %>
                              </td>
                          </tr>
                    <%} %>
                   <tr>
                       <td class="totalTime" id="<%=dao.weekDays[i]%>"></td>
                   </tr>
               </table>
                <% if (goalsPar != "all")
                   { %>
                    <div style="display: none;">
                        <% foreach (var newGoal in dao.GetAllGoals())
                           {
                               foreach (var newTask in dao.GetAllTasks(newGoal.Id))
                               {
                                   if (existingTask != null && existingTask != newTask)
                                   { %>
                                        <input class="inputBox" id="<%= dao.weekDays[i] %>-<%= week %>-<%= newTask.Id %>" value="<%= dao.GetTimeByWeekTaskDay(week, newTask.Id, dao.weekDays[i]) %>"/>
                                <% }
                               }
                           } %>
                    </div>
                <% }
           } %>
        
            <button id="editBtn" onclick="return editBtnClick();">Редактировать</button>
            <button id="saveBtn" onclick="return saveBtnClick();">Cохранить</button>

        </div>

        <div id="overlay"></div>

        <div id="addTaskPopUp">
            <div id="closeTaskPop"></div>
            <div class="popHeader">Добавить Новую Задачу</div>
            <div class="headerSeparator"></div>
            <div id="goalNameTxt" class="taskTxt">Имя цели:</div>
            <div id="taskNameTxt" class="taskTxt">Название новой задачи:</div>
            <div id="taskDescriptionTxt" class="taskTxt">Описание новой задачи:</div>
            <asp:TextBox runat="server" ID="goalNameTask"/>
            <asp:TextBox runat="server" ID="newTaskName"/>
            <asp:TextBox runat="server" ID="newTAskDescription" TextMode="multiline" Columns="50" Rows="5"/>
            <asp:Button runat="server" ID="addTaskBtn" Text="Добавить" OnClientClick="return validateTask();" OnClick="addTaskBtn_OnClick"/>
        </div>
        
        <div class="smallPop" id="descriptionPop">
            <div class="closeGoalPop"></div>
            <div class="popHeader">Описание Задачи</div>
            <div class="headerSeparator"></div>
            <div class="description"></div>
            <div class="taskStatus">Статус задачи: </div>
            <div class="status"></div>
            <button class="changeStatus">Изменить статус</button>
            <div id="taskIdField" style="display: none;"></div>
        </div>
    </form>
</body>
</html>
